/*
 * @Author: chen haoxuan
 * @Date: 2021-05-22 22:56:12
 * @LastEditTime: 2021-05-22 23:24:18
 */
#include<iostream>
#include<math.h>
using namespace std;
class Complex
{
    public:
        Complex(){real=0;imag=0;}
        Complex(double r,double i):real(r),imag(i){};
        void display();
        Complex operator+(Complex &c1);  //加
        Complex operator-(Complex &c1);  //减
        Complex operator*(Complex &c1);  //乘
        Complex operator/(Complex &c1);  //除
    private:
        double real;
        double imag;
};
// 加法
Complex Complex::operator+(Complex &c1)
{
    return Complex(real+c1.real,imag+c1.imag);
}
// 减法
Complex Complex::operator-(Complex &c1)
{
    
    return Complex(real-c1.real,imag-c1.imag);
}
// 乘法
Complex Complex::operator*(Complex &c1)
{
    return Complex(real*c1.real-imag*c1.imag,imag*c1.real-real*c1.imag);
}
// 除法
Complex Complex::operator/(Complex &c1)
{
    double temp=pow(c1.real,2)+pow(c1.imag,2);
    return Complex((real*c1.real+imag*c1.imag)/temp,imag*c1.real-real*c1.imag);
}
// 打印
void Complex::display()
{
    cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
    Complex c1(7,8),c2(4,6),c3,c4,c5,c6;
    c3=c1+c2;c3.display();
    c4=c1-c2;c4.display();
    c5=c1*c2;c5.display();
    c6=c1/c2;c6.display();  
    system("pause");
    return 0;
}